--[[
	合体飞机类
]]
local FitPlane = {}
local t_concat = table.concat
local t_rm 	= table.remove
local t_sort = table.sort
local math_ceil = math.ceil

local fitplane_mt = {__index = FitPlane}

local player_plane_size = {
	width = 186,
	height = 130,
}
 
 local enemy_plane_size = {
	width = 120,
	height = 79,
 }
 
 local bullet_size = {
	width = 62,
	height = 108,
 }

function FitPlane:ctor(idx, fitArray)
	self._idx = idx;
	self._posX = 0;
	self._posY = 0;
	self._speed = 0;
	self._width = 0;
	self._height = 0;
	self._firetime = 0;
	self._blood = 100;
	self._attack = 0;
	self._defensive = 0;
	self._survival = true;
	self._fitarray = fitArray or {}	-- 合体机的合体的子飞机id
	
	self._bulletid = -1;
	self._bulletacttype = -1;
end

function FitPlane:getInfo()
	return {
		idx = self._idx,
		posX = self._posX,
		posY = self._posY,
		speed = self._speed,
		width = self._width,
		height = self._height,
		blood = self._blood,
		attack = self._attack,
		defensive = self._defensive,
	}
end

function FitPlane:getFitArray()
	return self._fitarray;
end

function FitPlane:setPlaneData(data)
	self._posX = data.posX;
	self._posY = data.posY;
	self._width = data.width;
	self._height = data.height;
	self._firetime = data.firetime;
	self._blood = data.blood;
	self._attack = data.attack;
	self._defensive = data.defensive;
end

function FitPlane:setPositon(pos)
	self._posX = pos.nXpos or 0;
	self._posY = pos.nYpos or 0;
end

function FitPlane:getPosition()
	return 
	{
		nXpos = self._posX, 
		nYpos = self._posY,
	};
end

function FitPlane:isFire()
	if not self._survival then
		return false;
	end
	self._firetime = self._firetime - 1;
	if self._firetime <= 0 then
		self._firetime = 50;
		return true;
	end
	return false;
end

--受伤
function FitPlane:injured(object)
	-- 计算受伤值
	local jureBlood = object.attack - self._defensive
	self._blood = self._blood - jureBlood;
	local data = {
		bExist = false,
		disblood = 0,
	}
	data.disblood = -jureBlood;
	if self._blood <= 0 then
		data.bExist = false
	else 
		data.bExist = true
	end
	return data
end

--玩家出局
function FitPlane:playerOut()
	self._survival = false;
end

function FitPlane:isOut()
	return self._survival == false and true or false;
end

function FitPlane.new(...)
	local instance = {}
	setmetatable(instance, fitplane_mt)
	instance:ctor(...)
	return instance
end

return FitPlane
